package com.ziyue.socket.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.ziyue.socket.bean.Room;
import com.ziyue.socket.bean.activity.Activity;
import com.ziyue.socket.bean.change.ChangeActivityRequest;
import com.ziyue.socket.bean.init.ActivityInitRequest;
import com.ziyue.socket.cache.ActivityService;
import com.ziyue.socket.enums.OptionEnum;
import com.ziyue.socket.service.OptionAbstract;
import io.netty.channel.Channel;

import java.util.Date;

/**
 * Created by wancheng on 2019/4/20.
 */
public class ActivityInit extends OptionAbstract {

    private final OptionEnum OPTION = OptionEnum.ACTIVITY_INIT;
    @Override
    public Object send(Channel channel, String requestBody) throws Exception {
        ActivityInitRequest request = JSONObject.parseObject(requestBody, ActivityInitRequest.class);
        Activity activity = new Activity();
        activity.setActivityId(request.getActivityId());
        activity.setQuestionCount(request.getQuestionCount());
        activity.setStartTime(request.getStartTime());
        if (request.getLimit() != null){
            activity.setLimit(request.getLimit());
            Date endTime = new Date(request.getStartTime().getTime() + request.getLimit() * 1000);
            activity.setEndTime(endTime);
        }
        ActivityService.initActivity(channel,activity);
        sendMsg(channel,"初始化互动数据",activity,OPTION);
        return null;
    }

    @Override
    public Object get(Channel channel, String requestBody) {
        return null;
    }
}
